import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.regex.Pattern;

/**
 * @author ：陈奕安（3048279304@qq.com）
 * @date ：Created in 2025/5/28 10:49
 * @description：
 * @modified By：
 * @version:
 */
@WebFilter("/Dologin")
public class FilterLife implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        Filter.super.init(filterConfig);
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
     /*   HttpServletRequest request=(HttpServletRequest) servletRequest;
        String uname=request.getParameter("uname");
        String pwd=request.getParameter("pwd");
        String str1="^[0-9]{6}$";
        if (uname.length()>=6&& Pattern.matches(str1,pwd)&&"123456".equals(pwd)){
            filterChain.doFilter(servletRequest,servletResponse);
        }else {
            request.setAttribute("msg","密码必须大于六");
            request.getRequestDispatcher("login3.jsp").forward(servletRequest,servletResponse);
        }*/
        HttpServletRequest request=(HttpServletRequest) servletRequest;
        String uname=request.getParameter("uname");
        String pwd=request.getParameter("pwd");
        String str1="^[0-9]{6}$";
        if(uname.length()>=6&&Pattern.matches(str1,pwd)&&"123456".equals(pwd)){
            filterChain.doFilter(servletRequest,servletResponse);
        }
        else {
            request.setAttribute("msg","密码必须大于六");
            request.getRequestDispatcher("login3.jsp").forward(servletRequest,servletResponse);
        }
    }

    @Override
    public void destroy() {
        Filter.super.destroy();
    }



}